/*
 *  contiki-conf.h
 *
 *  Created on: 2018-3-9
 *      Author: Iron
 */

#ifndef CONTIKI_CONF_H_ESP32
#define CONTIKI_CONF_H_ESP32

/*----------------------------------------------------------------------------*/
#include <stdint.h>
#include <c_types.h> // ICACHE_FLASH_ATTR
#include <osapi.h>

// cc
/*----------------------------------------------------------------------------*/
#define WITH_ASCII 1

#define CC_CONF_REGISTER_ARGS          	1
#define CC_CONF_FUNCTION_POINTER_ARGS  	1
#define CC_CONF_VA_ARGS                	1
#define CC_CONF_INLINE 					inline

#define CC_CONF_UNSIGNED_CHAR_BUGS		0
#define	CC_CONF_NO_VA_ARGS				0
#define CC_CONF_DOUBLE_HASH				0
#define CC_NO_VA_ARGS					0

/*----------------------------------------------------------------------------*/
#ifndef CC_BYTE_ALIGNED
	#ifdef __GNUC__
		#define CC_BYTE_ALIGNED __attribute__ ((packed))
	#endif
#endif

#ifndef CC_BYTE_ALIGNED
	#define CC_BYTE_ALIGNED __attribute__ ((packed, aligned(1)))
#endif

// clock
/*----------------------------------------------------------------------------*/
#define CCIF
#define CLIF

typedef unsigned int  uip_stats_t;
typedef unsigned int  clock_time_t;
#define CLOCK_CONF_SECOND	100

typedef uint64_t rtimer_clock_t;
#define RTIMER_ARCH_SECOND      		32768
#define RTIMER_CLOCK_DIFF(a,b)     		((int64_t)((a)-(b)))

// contiki config
/*----------------------------------------------------------------------------*/
#define PROFILE_CONF_ON 				0
#define ENERGEST_CONF_ON 				0
//#define LOG_CONF_ENABLED				1
#define PROCESS_CONF_NO_PROCESS_NAMES 	0
#define AUTOSTART_ENABLE				0
#define PACKETBUF_CONF_ATTRS_INLINE 	0
#define CONTIKI_CONF_SETTINGS_MANAGER	0

// COOJA
#define CONTIKI_TARGET_COOJA			0
#define CONTIKI_TARGET_COOJA_IP64		0

// network config
/*---------------------------------------------------------------------------*/
/**
 * \name IPv6, RIME and network buffer configuration
 *
 * @{
 */
#define UIP_CONF_LOGGING					1

/* Addresses, Sizes and Interfaces */
/* 8-byte addresses here, 2 otherwise */
//#define LINKADDR_CONF_SIZE                   8
#define UIP_CONF_LL_802154                   1
#define UIP_CONF_LLH_LEN                     0
#define UIP_CONF_NETIF_MAX_ADDRESSES         3

/* TCP, UDP, ICMP */
#ifndef UIP_CONF_TCP
#define UIP_CONF_TCP                         1
#endif
#ifndef UIP_CONF_TCP_MSS
#define UIP_CONF_TCP_MSS                    64
#endif
#define UIP_CONF_UDP                         1
#define UIP_CONF_UDP_CHECKSUMS               0
#define UIP_CONF_ICMP6                       0
#define UIP_CONF_BROADCAST					 1	// UDP Broadcast

/* ND and Routing */
#ifndef UIP_CONF_ROUTER
#define UIP_CONF_ROUTER                      1
#endif

#define NETSTACK_CONF_WITH_IPV4 			 1
#define NETSTACK_CONF_WITH_IPV6 			 0
#define NETSTACK_CONF_WITH_RIME				 1

#ifndef UIP_CONF_MAX_ROUTES
#define UIP_CONF_MAX_ROUTES                 20
#endif

/* uIP */
#ifndef UIP_CONF_BUFFER_SIZE
#define UIP_CONF_BUFFER_SIZE              	1300
#endif

#ifndef PACKETBUF_CONF_SIZE
#define PACKETBUF_CONF_SIZE					250
#endif

// dhcp
#define UIP_CONF_DHCP_LIGHT

#define UIP_CONF_IP_FORWARD     	0	// slip forword

#if NETSTACK_CONF_WITH_IPV4 && NETSTACK_CONF_WITH_IPV6
	#error "IPV4 IPV6 conflict"
#endif

/* Default network config */
#if NETSTACK_CONF_WITH_IPV6
	#define NULLRDC_CONF_802154_AUTOACK  				1
	#define NULLRDC_CONF_SEND_802154_ACK 				1
	#define NULLRDC_CONF_ACK_WAIT_TIME                	RTIMER_SECOND / 500
	#define NULLRDC_CONF_AFTER_ACK_DETECTED_WAIT_TIME 	0

	/* Network setup for IPv6 */
	#define NETSTACK_CONF_NETWORK       sicslowpan_driver
	#define NETSTACK_CONF_MAC           csma_driver
	#define NETSTACK_CONF_RDC           nullrdc_driver
	#define NETSTACK_CONF_RADIO         cooja_radio_driver
	#define NETSTACK_CONF_FRAMER        framer_802154
#else /* NETSTACK_CONF_WITH_IPV6 */
	#if NETSTACK_CONF_WITH_IPV4
		/* Network setup for IPv4 */
		#define NETSTACK_CONF_NETWORK 	rime_driver 		/* NOTE: uip_over_mesh. else: uip_driver */
		#define NETSTACK_CONF_MAC 		nullmac_driver
		#define NETSTACK_CONF_RDC 		nullrdc_driver
		#define NETSTACK_CONF_RADIO 	espnow_radio_driver // nullradio_driver // cooja_radio_driver
	#else /* NETSTACK_CONF_WITH_IPV4 */
		/* Network setup for Rime */
		#define NETSTACK_CONF_NETWORK 	rime_driver
		#define NETSTACK_CONF_MAC 		nullmac_driver // csma_driver
		#define NETSTACK_CONF_RDC 		nullrdc_driver
		#define NETSTACK_CONF_RADIO 	espnow_radio_driver // cooja_radio_driver
		/*#define NETSTACK_CONF_FRAMER framer_nullmac*/
	#endif /* NETSTACK_CONF_WITH_IPV4 */
#endif /* NETSTACK_CONF_WITH_IPV6 */

// slip
/*----------------------------------------------------------------------------*/
/* Turn off example-provided putchars */
#define SLIP_BRIDGE_CONF_NO_PUTCHAR 1

// rime config
/*----------------------------------------------------------------------------*/
#define RIMESTATS_CONF_ENABLED 		0
#define RIMESTATS_CONF_ON 			0

/*----------------------------------------------------------------------------*/
#define RF_CHANNEL	12

/*----------------------------------------------------------------------------*/
#include "project-conf.h"
#include "contiki-default-conf.h"

/*----------------------------------------------------------------------------*/
#endif // CONTIKI_CONF_H_ESP32
